#ifndef SESSIONHANDLER_H
#define SESSIONHANDLER_H

#include "resip/dum/ServerInviteSession.hxx"
#include "resip/dum/InviteSessionHandler.hxx"

#include <string>
#include <iostream>

class Controller;


class SessionHandler : public resip::InviteSessionHandler
{
public:
	// Constructor & Destructor

	SessionHandler(Controller* parent);
	virtual ~SessionHandler();

	// Memberfunctions

	void initialize();
	void cleanup();

	bool isDone(){ return m_done; }
	void setDone(bool done){ m_done = done; }

	void hangup();

	// Callbacks: InviteSessionHandler

	virtual void onNewSession(resip::ClientInviteSessionHandle h, resip::InviteSession::OfferAnswerType oat, const resip::SipMessage& msg){;}  
	virtual void onNewSession(resip::ServerInviteSessionHandle h, resip::InviteSession::OfferAnswerType oat, const resip::SipMessage& msg);
	virtual void onFailure(resip::ClientInviteSessionHandle h, const resip::SipMessage& msg){;}      
	virtual void onProvisional(resip::ClientInviteSessionHandle h, const resip::SipMessage& msg){;}
	virtual void onConnected(resip::ClientInviteSessionHandle h, const resip::SipMessage& msg){;}
	virtual void onConnectedConfirmed(resip::InviteSessionHandle h, const resip::SipMessage & msg);
	virtual void onStaleCallTimeout(resip::ClientInviteSessionHandle handle){;}
	virtual void onConnected(resip::InviteSessionHandle h, const resip::SipMessage& msg){;}
	virtual void onRedirected(resip::ClientInviteSessionHandle h, const resip::SipMessage& msg){;}
	virtual void onTerminated(resip::InviteSessionHandle h, resip::InviteSessionHandler::TerminatedReason reason, const resip::SipMessage* msg){;}
	virtual void onAnswer(resip::InviteSessionHandle h, const resip::SipMessage& msg, const resip::SdpContents& sdp);
	virtual void onAckReceived(resip::InviteSessionHandle h, const resip::SipMessage & msg);
	virtual void onOffer(resip::InviteSessionHandle is, const resip::SipMessage& msg, const resip::SdpContents& sdp);      
	virtual void onEarlyMedia(resip::ClientInviteSessionHandle h, const resip::SipMessage& msg, const resip::SdpContents& sdp){;}
	virtual void onOfferRequired(resip::InviteSessionHandle h, const resip::SipMessage& msg);
	virtual void onOfferRejected(resip::InviteSessionHandle h, const resip::SipMessage* msg){;}
	virtual void onDialogModified(resip::InviteSessionHandle h, resip::InviteSession::OfferAnswerType oat, const resip::SipMessage& msg){;}
	virtual void onRefer(resip::InviteSessionHandle h, resip::ServerSubscriptionHandle, const resip::SipMessage& msg){;}
	virtual void onReferAccepted(resip::InviteSessionHandle h, resip::ClientSubscriptionHandle, const resip::SipMessage& msg){;}
	virtual void onReferRejected(resip::InviteSessionHandle h, const resip::SipMessage& msg){;}
	virtual void onReferNoSub(resip::InviteSessionHandle h, const resip::SipMessage& msg){;}
	virtual void onInfo(resip::InviteSessionHandle h, const resip::SipMessage& msg){;}
	virtual void onInfoSuccess(resip::InviteSessionHandle h, const resip::SipMessage& msg){;}
	virtual void onInfoFailure(resip::InviteSessionHandle h, const resip::SipMessage& msg){;}
	virtual void onMessage(resip::InviteSessionHandle h, const resip::SipMessage& msg){;}
	virtual void onMessageSuccess(resip::InviteSessionHandle h, const resip::SipMessage& msg){;}
	virtual void onMessageFailure(resip::InviteSessionHandle h, const resip::SipMessage& msg){;}
	virtual void onForkDestroyed(resip::ClientInviteSessionHandle h){;}

private:
	// Memberfunctions

	std::string parseContactName(std::string from);

	// Membervariables

	bool m_done;
	Controller* m_owner;

	resip::ServerInviteSessionHandle m_sis;
};

#endif